
package section2.series; 
import jgfutil.*; 
import java.util.Arrays;

public class SeriesOCLTest 
{

	
native float[] seriesFromC(int slice, float omega, int array_rows, int nthreads); 

static {
	System.loadLibrary("series");
}

	
// Declare class data.

static int array_rows; 
public static float [] [] TestArray;  // Array of arrays.
   

   

/*
* buildTestData
*
*/

// Instantiate array(s) to hold fourier coefficients.

void buildTestData()
{
    // Allocate appropriate length for the double array of floats.

    TestArray = new float [2][array_rows];
}



/*
* Do
*
* This consists of calculating the
* first n pairs of fourier coefficients of the function (x+1)^x on
* the interval 0,2. n is given by array_rows, the array size.
* NOTE: The # of integration steps is fixed at 1000. 
*/

void Do()
{
    
    int i,j;
    
    float omega;       // Fundamental frequency.
	int ilow,iupper,slice;
	
    omega = (float) 3.1415926535897932;

    slice = (SeriesOCLTest.array_rows + JGFSeriesOCLBench.nthreads-1)/JGFSeriesOCLBench.nthreads; 
    
    // Start the stopwatch.
    float [] resArray;
    JGFInstrumentor.startTimer("Section2:Series:Kernel"); 

    resArray = seriesFromC(slice, omega, SeriesOCLTest.array_rows, JGFSeriesOCLBench.nthreads);
    TestArray[0] = Arrays.copyOfRange(resArray, 0, SeriesOCLTest.array_rows);
    TestArray[1] = Arrays.copyOfRange(resArray, SeriesOCLTest.array_rows, SeriesOCLTest.array_rows*2);

 
    // Stop the stopwatch.

    JGFInstrumentor.stopTimer("Section2:Series:Kernel"); 

}
void freeTestData()
{
    TestArray = null;    // Destroy the array.
    System.gc();         // Force garbage collection.
}



}

















